package leetcode.code0565;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int arrayNesting(int[] nums) {
		int len = nums.length;
		int[] hash = new int[len];
		int p = 1;
		int ans = 0;
		for (int i = 0; i < hash.length; i++) {
			if (hash[i] == 0) {
				int cur = 0, index = i;
				while (hash[index] == 0) {
					hash[index] = p;
					index = nums[index];
					cur++;
				}
				if (hash[index] == p) {
					ans = Math.max(ans, cur);
				}
				p++;
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
